






detritus = zeros(366,1);
detritus(1) = 4;

fish = zeros(366,1);
fish(1) = 5;

P = zeros(366,1);
P(1) = 10;

phyt = zeros(366,1);
phyt(1) = 8;
 
zoopl = zeros(366,1);
zoopl(1) = 0.15;

submerged = zeros(366,1);
submerged(1) = 8;

sediment = zeros(366,1);
sediment(1) = 0.04;

porewater = zeros(366,1);
porewater(1) = 0.05;

m_phyt = zeros(366,1);
m_zoo = zeros(366,1);
m_fish = zeros(366,1);
m_sub = zeros(366,1);
mine_detritus = zeros(366,1);
pr = zeros(366,1);
in_P = zeros(366,1);
diffuse_porewater = zeros(366,1);
uptake_phyt = zeros(366,1);
out_P = zeros(366,1);
absorb_submerged = zeros(366,1);
outfl = zeros(366,1);
gr = zeros(366,1);
dissolve_sediment = zeros(366,1);


dt=1;
qv = 0.0125;
qvout = 0.0125;

for t = 1:366
    if t~=1
        detritus(t) = detritus(t-dt) + (m_phyt(t-dt) + m_zoo(t-dt) + m_fish(t-dt) + m_sub(t-dt) - mine_detritus(t-dt) - gr(t-dt) ) * dt;
        fish(t) = fish(t-dt) + (pr(t-dt) - m_fish(t-dt)) * dt;
        P(t) = P(t-dt) + (in_P(t-dt) + diffuse_porewater(t-dt) - uptake_phyt(t-dt) - out_P(t-dt) - absorb_submerged(t-dt)) * dt;
        phyt(t) = phyt(t-dt) + (uptake_phyt(t-dt) - outfl(t-dt) - m_phyt(t-dt)) * dt;
        zoopl(t) = zoopl(t-dt) + (gr(t-dt) - pr(t-dt) - m_zoo(t-dt)) * dt;
        submerged(t) = submerged(t-dt) + ( absorb_submerged(t-dt) - m_sub(t-dt) ) * dt;
        sediment(t) = sediment(t-dt) + ( mine_detritus(t-dt) - dissolve_sediment(t-dt) ) * dt;
        porewater(t) = porewater(t-dt) + ( dissolve_sediment(t-dt) - diffuse_porewater(t-dt) ) * dt;

    end
    
    m_phyt(t) = 0.01 * phyt(t);
    m_zoo(t) = 0.01 * zoopl(t);
    m_fish(t) = 0.012 * fish(t);
    m_sub(t) = 0.02 * submerged(t);

    mine_detritus(t) = 0.004 * detritus(t);
    
    pr(t) = 0.125 * fish(t) * (zoopl(t) - 0.1) / (zoopl(t) + 0.3);
    
    in_P(t) =  20 * qv;
    
    diffuse_porewater(t) = 0.004 * porewater(t);
    
    uptake_phyt(t) = 0.08 * phyt(t) * (P(t) - 5) / (P(t) + 10);
    
    out_P(t) = P(t) * qvout;
    
    absorb_submerged(t) = 0.08 * submerged(t) * ( P(t) - 5 ) / (P(t) + 10);
    
    outfl(t) = phyt(t) * qvout;
    
    gr(t) = 0.4 * zoopl(t) * ( phyt(t) - 0.1 ) / ( phyt(t) + 0.5 );
    
    dissolve_sediment(t) = 0.003 * sediment(t);


end

result = detritus + fish + P + phyt + zoopl + submerged + sediment + porewater;